import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/manager/network/xindong_networking.dart';
import 'package:xindong/models/xindong_noble_privilege_class.dart';
import 'package:xindong/routes/user/noble/xindong_noble_ctr.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/widgets/container/xindong_empty_container.dart';

class XinDongNoblePrivilegeGridView extends StatelessWidget {
  const XinDongNoblePrivilegeGridView({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.all(16),
      decoration: BoxDecoration(color: DZColors.cellColor, borderRadius: BorderRadius.circular(16)),
      child: GetBuilder<XinDongNobleCtr>(
          id: "model",
          builder: (controller) {
            final dataList = controller.selectClass?.privilege.values.toList();
            return Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Container(
                  height: 44,
                  alignment: Alignment.center,
                  child: Text("-- ${controller.selectClass?.name}特权 --", style: const TextStyle(color: DZColors.titleColor),),
                ),
                XinDongEmptyContainer(
                  dataList: dataList,
                  child: AlignedGridView.count(
                    itemCount: dataList?.length ?? 0,
                    padding: const EdgeInsets.only(bottom: 10),
                    crossAxisCount: 3,
                    mainAxisSpacing: 0,
                    crossAxisSpacing: 0,
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    itemBuilder: (BuildContext context, int index) {
                      final model = dataList![index];
                      return gridItem(model);
                    },
                  ),
                ),
              ],
            );
          }),
    );
  }

  Widget gridItem(XinDongNoblePrivilegeClass model) {
    return SizedBox(
      height: 76,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          ImageUtil.networkImageUrl(XinDongNetworking.instance.fileUrl + model.icon, width: 46, height: 46),
          Text(
            model.name,
            style: const TextStyle(color: DZColors.contentColor, fontSize: 12, fontWeight: FontWeight.w500),
          ),
        ],
      ),
    );
  }
}
